package cn.heima.cn;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class Demo {
    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>(
                new Comparator<Student>() {
                    @Override
                    public int compare(Student o1, Student o2) {
                       int result = o1.getAge()-o2.getAge();
                      result = result==0?o1.getName().compareTo(o2.getName()):result;
                        return result;
                    }
                }
        );
        Student student1 = new Student("zhangshang",24,"男");
        Student student2 = new Student("lisi",23,"女");
        Student student3 = new Student("wangwu",25,"男");
        Student student4 = new Student("zhaoliu",26,"女");
        ts.add(student1);
        ts.add(student2);
        ts.add(student3);
        ts.add(student4);
        Iterator<Student> it = ts.iterator();
        while(it.hasNext()){
            Student next = it.next();
            System.out.println(next);
        }

    }
}
